package com.test.client.filetransfer;

import org.apache.log4j.Logger;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;

public class FileTransferManager extends Thread{
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(FileTransferManager.class);

	ObjectInputStream ois;
	Socket socket;

	public FileTransferManager(Socket socket) {
		this.socket = socket;
		try {
			ois = new ObjectInputStream(socket.getInputStream());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void run(){
		if (logger.isDebugEnabled()) {
			logger.debug("run() - start"); //$NON-NLS-1$
		}

		try {
			FileDto fileDto = (FileDto)ois.readObject();
			
			
			Thread t = new Thread(new FileReceive(fileDto,socket));
			t.start();
			
//			new FileReceive(fileDto,socket);
			
		} catch (IOException e) {
			logger.error("run()", e); //$NON-NLS-1$

			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			logger.error("run()", e); //$NON-NLS-1$

			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		if (logger.isDebugEnabled()) {
			logger.debug("run() - end"); //$NON-NLS-1$
		}
	}
}
